package bb.lanxing.util.thread;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class ThreadPools {
    public static final String COMMON_POOL = "common";
    private static ThreadPools instance = new ThreadPools();
    private Map<String, ThreadPool> threadPools = new HashMap();

    private ThreadPools() {
    }

    public static final ThreadPools getInstance() {
        return instance;
    }

    public void createPool(String str, int i) {
        this.threadPools.put(str, new ThreadPool(str, i, i, 0L, TimeUnit.MILLISECONDS));
    }

    public void addTask(Runnable runnable) {
        ThreadPool threadPool = this.threadPools.get(COMMON_POOL);
        if (threadPool == null) {
            createPool(COMMON_POOL, 4);
            threadPool = this.threadPools.get(COMMON_POOL);
            threadPool.prestartAllCoreThreads();
        }
        threadPool.execute(runnable);
    }
}